var e = require;
var t = module;
var o = exports;
var n;
function i(e, t) {
    return (i =
        Object.setPrototypeOf ||
        function (e, t) {
            return (e.__proto__ = t), e;
        })(e, t);
}
(o.__esModule = !0), (o.default = void 0);
var a = (function (e) {
    var t, o;
    function n() {
        var t;
        return (
            ((t = e.call(this) || this).moreGamePortal = null),
            (t.moreGameBanner = null),
            (t.moreGameBannerLeft = 16),
            (t.moreGameBannerTop = 16),
            (t.multiMoreGameBanner = []),
            t
        );
    }
    (o = e), ((t = n).prototype = Object.create(o.prototype)), (t.prototype.constructor = t), i(t, o);
    var a = n.prototype;
    return (
        (a.init = function () {
            (this.env = window.qq),
                (this.info = (window.lplatform && lplatform.systemInfo) || this.env.getSystemInfoSync()),
                (this.bh = lplatform.cparam.bannerHeight || 170),
                (this.bw = lplatform.cparam.bannerWidth || Math.min(this.info.windowWidth, (16 * this.bh) / 9)),
                (this.logined = !1),
                this.showShareMenu(),
                this.checkLogin();
        }),
        (a.initAD = function () {
            this.loadBanner(!1), this.loadInterstitial(!1), this.createRewardedVideo(!1);
        }),
        (a.checkLogin = function () {
            var e = this;
            e.env.checkSession({
                success: function success() {
                    e.logined = !0;
                },
                fail: function fail() {
                    e.env.login({
                        success: function success(t) {
                            t.code ? (e.logined = !0) : console.log("登录失败！" + t.errMsg);
                        }
                    });
                }
            });
        }),
        (a.showFavoriteGuide = function () {
            this.env.addToFavorites({
                title: "加关注，不迷路。",
                imageUrl: "",
                query: "a=1&b=2",
                success: function success() {},
                fail: function fail(e) {
                    console.log("addToFavorites fail", e);
                },
                complete: function complete() {}
            }),
                setTimeout(
                    function () {
                        this.saveAppToDesktop();
                    }.bind(this),
                    15e3
                ),
                setTimeout(
                    function () {
                        this.addRecentColorSign();
                    }.bind(this),
                    1e5
                );
        }),
        (a.showShareMenu = function () {
            "function" == typeof this.env.showShareMenu &&
                this.env.showShareMenu({showShareItems: ["qq", "qzone", "wechatFriends", "wechatMoment"]}),
                this.env.onShareAppMessage(function () {
                    return (
                        lplatform.plog(
                            "onShareAppMessage lplatform.cparam.shareAppImgUrl:" + lplatform.cparam.shareAppImgUrl
                        ),
                        {title: lplatform.cparam.shareAppTitle, imageUrl: lplatform.cparam.shareAppImgUrl}
                    );
                });
        }),
        (a.shareAppMessage = function (e, t) {
            lplatform.plog("shareAppMessage lplatform.cparam.shareAppImgUrl:" + lplatform.cparam.shareAppImgUrl),
                this.env.shareAppMessage({
                    title: lplatform.cparam.shareAppTitle,
                    imageUrl: lplatform.cparam.shareAppImgUrl,
                    success: function success() {
                        e && e();
                    },
                    fail: function fail() {
                        t && t();
                    }
                });
        }),
        (a.shareRecord = function (e, t) {
            this.shareAppMessage(e, t);
        }),
        (a.makeShareUI = function (e, t, o, n, i) {
            void 0 === n && (n = 0),
                void 0 === i && (i = !1),
                lplatform.uiEngine.CreateShareK(
                    function () {
                        this.shareRecord(e, t);
                    }.bind(this),
                    function () {
                        t && t(), this.gameRecordShareBtn && this.gameRecordShareBtn.hide();
                    }.bind(this),
                    o,
                    n,
                    !1
                );
        }),
        (a.showInterstitial = function () {
            var e = this;
            this.insterstitialAd
                ? this.insterstitialAd.show().catch(function (t) {
                      lplatform.plog("showInterstitial cache:" + JSON.stringify(t));
                      var o = e;
                      lplatform.labData.mainSwitch && o.createMoreGamePortal(!1, !0);
                  })
                : this.loadInterstitial(!0);
        }),
        (a.hideInterstitial = function () {
            this.insterstitialAd, this.moreGamePortal && this.moreGamePortal.destroy();
        }),
        (a.createMoreGamePortal = function (e, t) {
            if (
                (void 0 === e && (e = !1),
                void 0 === t && (t = !0),
                lplatform.plog("QQ createMoreGamePortal typeof this.env.createAppBox:" + typeof this.env.createAppBox),
                "function" == typeof this.env.createAppBox &&
                    lplatform.cparam.moreGamePortalAppId &&
                    lplatform.cparam.moreGamePortalAppId.length > 0)
            ) {
                if (
                    (e && this.moreGamePortal && (this.moreGamePortal.destroy(), (this.moreGamePortal = null)),
                    lplatform.plog("QQ createMoreGamePortal this.moreGamePortal:" + this.moreGamePortal),
                    !this.moreGamePortal)
                ) {
                    var o = Math.floor(Math.random() * lplatform.cparam.moreGamePortalAppId.length),
                        n = lplatform.cparam.moreGamePortalAppId[o];
                    lplatform.plog("QQ createMoreGamePortal baid:" + n),
                        (this.moreGamePortal = this.env.createAppBox({adUnitId: n}));
                }
                lplatform.plog("QQ createMoreGamePortal autoShow:" + t);
                var i = this;
                this.moreGamePortal
                    .load()
                    .then(function () {
                        t && i.moreGamePortal.show();
                    })
                    .catch(function (e) {
                        lplatform.plog("moreGamePortal load catch:" + JSON.stringify(e));
                    });
            }
        }),
        (a.showRealBanner = function () {
            this.bannerAd ? this.bannerAd.show() : this.loadBanner(!0);
        }),
        (a.showBanner = function () {
            this.hideBanner(),
                lplatform.labData.mainSwitch,
                Math.random() <= lplatform.cparam.moreGameBannerPercent
                    ? this.createMoreGameBanner(!0, !0)
                    : this.showRealBanner();
        }),
        (a.hideBanner = function (e) {
            void 0 === e && (e = !1),
                this.bannerAd &&
                    (this.bannerAd.hide(),
                    e &&
                        (this.bannerAd.offLoad(this.onBannerLoad),
                        this.bannerAd.offError(this.onBannerError),
                        this.bannerAd.offResize(this.onBannerResize),
                        this.bannerAd.destroy(),
                        (this.bannerAd = null))),
                this.moreGameBanner && this.moreGameBanner.hide();
        }),
        (a.hideMoreGameBanner = function () {
            this.moreGameBanner &&
                (this.moreGameBanner.offResize(function () {}),
                this.moreGameBanner.offLoad(function () {}),
                this.moreGameBanner.offError(function () {}),
                this.moreGameBanner.destroy(),
                (this.moreGameBanner = null));
        }),
        (a.createMoreGameBanner = function (e, t) {
            if (
                (void 0 === e && (e = !1),
                void 0 === t && (t = !1),
                lplatform.plog(
                    "QQ createMoreGameBanner typeof this.env.createBlockAd:" + typeof this.env.createBlockAd
                ),
                "function" == typeof this.env.createBlockAd)
            ) {
                var o = this;
                if (
                    lplatform.cparam.moreGameBannerAppId &&
                    (e &&
                        this.moreGameBanner &&
                        (this.moreGameBanner.offResize(function () {}),
                        this.moreGameBanner.offLoad(function () {}),
                        this.moreGameBanner.offError(function () {}),
                        this.moreGameBanner.destroy(),
                        (this.moreGameBanner = null)),
                    !this.moreGameBanner)
                ) {
                    var n = Math.floor(Math.random() * lplatform.cparam.moreGameBannerAppId.length),
                        i = lplatform.cparam.moreGameBannerAppId[n];
                    lplatform.plog(
                        "QQ createMoreGameBanner baid:" +
                            i +
                            " this.moreGameBannerLeft:" +
                            this.moreGameBannerLeft +
                            " this.moreGameBannerTop:" +
                            this.moreGameBannerTop
                    ),
                        (this.moreGameBanner = this.env.createBlockAd({
                            adUnitId: i,
                            style: {
                                left: Math.max(0, this.moreGameBannerLeft),
                                top: Math.max(0, this.moreGameBannerTop)
                            },
                            size: 5,
                            orientation: "landscape"
                        })),
                        this.moreGameBanner.onResize(function (e) {
                            (o.moreGameBannerTop = 0),
                                lplatform.cparam.bannerOnBottom &&
                                    (o.moreGameBannerTop = o.info.windowHeight - e.height - 20),
                                (o.moreGameBanner.style.top = Math.max(0, o.moreGameBannerTop)),
                                (o.moreGameBanner.style.left = Math.max(0, (o.info.windowWidth - e.width) / 2)),
                                lplatform.plog(
                                    "QQ createMoreGameBanner onResize size:" +
                                        JSON.stringify(e) +
                                        " top:" +
                                        o.moreGameBanner.style.top +
                                        " left:" +
                                        o.moreGameBanner.style.left
                                );
                        }),
                        this.moreGameBanner.onLoad(function () {
                            lplatform.plog("QQ createMoreGameBanner onLoad autoShow:" + t),
                                t && o.moreGameBanner.show();
                        }),
                        this.moreGameBanner.onError(function (e) {
                            lplatform.plog("QQ createmoreGameBanner onError res:" + JSON.stringify(e));
                        });
                }
            }
        }),
        (a.createOutMoreGameBanner = function (e, t, o, n) {
            var i = e.x,
                a = e.y,
                r = this.env.createBlockAd({
                    adUnitId: n,
                    style: {left: i, top: a},
                    size: t || 1,
                    orientation: o || "vertical"
                });
            return (
                r.onResize(function (t) {
                    (r.style.left = Math.max(0, e.x - t.width / 2 / 1)),
                        (r.style.top = Math.max(0, e.y - t.height / 2 / 1));
                }),
                r.onLoad(function () {
                    r.show();
                }),
                r.onError(function (e) {
                    lplatform.plog("QQ createOutMoreGameBanner onError res:" + JSON.stringify(e));
                }),
                r
            );
        }),
        (a.createMultiMoreGameBanner = function () {
            for (var e = 0; e < lplatform.cparam.mmgPos.length; e++) {
                if (
                    (this.multiMoreGameBanner[e] &&
                        (this.multiMoreGameBanner[e].offResize(function () {}),
                        this.multiMoreGameBanner[e].offLoad(function () {}),
                        this.multiMoreGameBanner[e].offError(function () {}),
                        this.multiMoreGameBanner[e].destroy(),
                        (this.multiMoreGameBanner[e] = null)),
                    !this.multiMoreGameBanner[e])
                ) {
                    var t = {
                            x: this.info.windowWidth * lplatform.cparam.mmgPos[e].x,
                            y: this.info.windowHeight * lplatform.cparam.mmgPos[e].y
                        },
                        o = lplatform.cparam.mmgSize[e],
                        n = lplatform.cparam.mmgOrientation[e],
                        i = lplatform.cparam.mmgId[e];
                    this.multiMoreGameBanner[e] = this.createOutMoreGameBanner(t, o, n, i);
                }
            }
        }),
        (a.showMultiMoreGameBanner = function () {
            this.createMultiMoreGameBanner();
        }),
        (a.hideMultiMoreGameBanner = function () {
            for (var e = 0; e < this.multiMoreGameBanner.length; e++) {
                this.multiMoreGameBanner[e] && this.multiMoreGameBanner[e].hide();
            }
        }),
        (a.canRecord = function () {
            return console.log("不支持录制游戏画面"), !1;
        }),
        (a.canShareRecord = function () {
            return !0;
        }),
        (a.goToGameOrGameList = function () {
            lplatform.plog("qq未实现 goToGameOrGameList");
        }),
        (a.shareMessageToFriend = function () {}),
        (a.saveAppToDesktop = function () {
            this.env.saveAppToDesktop({
                success: function success() {},
                fail: function fail() {},
                complete: function complete() {}
            });
        }),
        (a.subscribeAppMsg = function () {
            this.env.subscribeAppMsg({
                tmplIds: lplatform.cparam.tmplIds,
                subscribe: !0,
                success: function success(e) {
                    console.log("----subscribeAppMsg----success", e);
                },
                fail: function fail(e) {
                    console.log("----subscribeAppMsg----fail", e);
                }
            });
        }),
        (a.sendMsgToOpenDataProject = function (t) {
            this.logined ? e.prototype.sendMsgToOpenDataProject.call(this, t) : this.checkLogin();
        }),
        (a.setUserCloudStorage = function (e) {
            this.sendMsgToOpenDataProject({name: "setUserCloudStorage", kvdata: e});
        }),
        (a.addRecentColorSign = function () {
            this.env.addRecentColorSign({
                query: "a=1&b=2",
                success: function success() {},
                fail: function fail(e) {
                    console.log("addRecentColorSign fail: ", e);
                },
                complete: function complete() {}
            });
        }),
        n
    );
})(((n = e("PWX")) && n.__esModule ? n : {default: n}).default);
(o.default = a), (t.exports = o.default);
